package com.tensquare.article.rest;

import com.netflix.discovery.converters.Auto;
import com.tensquare.article.service.ArticleService;
import com.tensquare.entity.Comment;
import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("comment")
public class CommentRest {

    @Autowired
    ArticleService articleService;


    /**
     * 文章评论
     * @param comment
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody Comment comment){
        articleService.addComment(comment);
        return new Result(true, StatusCode.OK, "评论成功");
    }

    /**
     * 根据文章id查询全部评论
     * @param articleid
     * @return
     */
    @RequestMapping(value = "findByArticleid/{articleid}", method = RequestMethod.GET)
    public Result findByArticleid(@PathVariable("articleid") String articleid){

        return new Result(true, StatusCode.OK, "查询成功", articleService.findByArticleid(articleid));
    }

    /**
     * 根据id删除评论
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    public Result delete(@PathVariable("id") String id){
        articleService.deleteComment(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }
}
